package com.bjsdzk.collector.utils;

import com.bjsdzk.collector.constant.Constant;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.mongo.MongoClient;
import io.vertx.ext.mongo.UpdateOptions;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author sl
 */
@Slf4j
public class MongoUtils {

    public static void updateMongo(MongoClient mongoClient,JsonObject data, JsonObject query ) {
        JsonObject update = new JsonObject().put("$set", data);
        UpdateOptions options = new UpdateOptions().setMulti(false).setUpsert(true);
        mongoClient.updateCollectionWithOptions(Constant.MONGONAME_REAL, query, update, options, res -> {
            if (res.failed()) {
                log.error("deviceId:{} update error ", data.getString("deviceId"));
            }
        });
    }
}
